Skip to content

fix: add Trae command adapter for slash commands support#1193

Open
studyzy wants to merge 2 commits into
Fission-AI:mainfrom
studyzy:fix/trae_commands
Open

fix: add Trae command adapter for slash commands support#1193
studyzy wants to merge 2 commits into
Fission-AI:mainfrom
studyzy:fix/trae_commands

Conversation

@studyzy

@studyzy studyzy commented Jun 10, 2026

Copy link
Copy Markdown

Summary

Fixes a bug where openspec init --tools trae did not generate any commands because the Trae adapter was never registered in CommandAdapterRegistry.init().

Changes

  • src/core/command-generation/adapters/trae.ts (new): Trae command adapter. Writes to .trae/commands/opsx/<id>.md with bare command ID as the name field (per Trae convention).
  • src/core/command-generation/adapters/index.ts: Export traeAdapter.
  • src/core/command-generation/registry.ts: Register traeAdapter in CommandAdapterRegistry.init().

Root Cause

The adapter file and export were missing entirely — CommandAdapterRegistry.init() had no entry for Trae, so the tool was silently skipped during init.

Testing

All existing tests pass (npm test). The test/core/command-generation/adapters.test.ts suite (92 tests) covers adapter formatting and confirms the fix works correctly.

Summary by CodeRabbit

  • New Features

    • Added Trae command generation: commands are now output in .trae/commands/opsx/.md using Trae-style YAML frontmatter (name, description) plus command body; YAML values are safely escaped.
  • Documentation

    • Updated supported tools list to include the Trae adapter and its command path.
  • Tests

    • Added tests covering Trae formatting, paths, registry presence, and YAML escaping.

Adds a command adapter for Trae so that 'openspec init --tools trae'
generates commands in .trae/commands/opsx/ directory.

Per Trae's convention, the command name uses the bare ID (e.g., 'apply')
instead of the prefixed format used by Claude (e.g., 'OPSX: Apply').

Fixes missing Trae adapter registration in CommandAdapterRegistry.init().
@studyzy studyzy requested a review from TabishB as a code owner June 10, 2026 02:19
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 85fd3b9e-51c8-4e6f-a5d2-91aa61d6a4e5

📥 Commits

Reviewing files that changed from the base of the PR and between 8453821 and 7b5b114.

📒 Files selected for processing (4)
  • docs/supported-tools.md
  • src/core/command-generation/adapters/trae.ts
  • test/core/command-generation/adapters.test.ts
  • test/core/command-generation/registry.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/command-generation/adapters/trae.ts

📝 Walkthrough

Walkthrough

Adds a Trae tool command adapter that emits markdown files at .trae/commands/opsx/<id>.md with YAML frontmatter (name, description) and body content, exports it from the adapters index, registers it in the CommandAdapterRegistry, updates docs, and adds tests validating paths and YAML escaping.

Changes

Trae Adapter Integration

Layer / File(s) Summary
Trae adapter core and YAML escaping
src/core/command-generation/adapters/trae.ts
Adds escapeYamlValue() and traeAdapter implementing ToolCommandAdapter: formats YAML frontmatter (name from content.id, description from content.description) and emits markdown at .trae/commands/opsx/<commandId>.md followed by content.body.
Export from adapters index and registry registration
src/core/command-generation/adapters/index.ts, src/core/command-generation/registry.ts
Re-exports traeAdapter from the adapters barrel and imports+registers it in CommandAdapterRegistry static initializer so trae is discoverable via get, getAll, and has.
Docs and tests updates
docs/supported-tools.md, test/core/command-generation/adapters.test.ts, test/core/command-generation/registry.test.ts
Docs list Trae’s generated command path pattern. Tests add traeAdapter import and describe('traeAdapter') assertions for toolId, file paths, YAML frontmatter content/escaping, omission of category/tags, and registry presence; registry tests updated to include trae.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Fission-AI/OpenSpec#556: Adds the adapter/registry framework that this PR extends by registering traeAdapter.
  • Fission-AI/OpenSpec#886: Adds another ToolCommandAdapter and wires it through the same adapters index and registry patterns.

Suggested reviewers

  • TabishB
  • alfred-openspec

Poem

I’m a rabbit with a YAML hat,
Hopping .trae/commands/opsx just like that,
Names and descriptions snug and quoted,
Tests say paths are neatly noted,
Registry greets the adapter — tip my whiskers! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a Trae command adapter to enable slash command support, which directly addresses the bug fix outlined in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/command-generation/adapters/trae.ts`:
- Around line 23-31: formatFile in adapters/trae.ts injects content.id and
content.description directly into YAML frontmatter causing invalid YAML when
values contain special characters; update formatFile to use the same
escapeYamlValue utility used by sibling adapters (e.g., claude.ts, cursor.ts) to
sanitize both the name and description before interpolation. Locate the
formatFile method and replace direct interpolation of content.id and
content.description with escaped values (call escapeYamlValue(content.id) and
escapeYamlValue(content.description)), ensuring description remains quoted in
the frontmatter as in other adapters.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 994aa242-f91e-4b26-80ad-06f65cd96244

📥 Commits

Reviewing files that changed from the base of the PR and between 1b06fdd and 8453821.

📒 Files selected for processing (3)
  • src/core/command-generation/adapters/index.ts
  • src/core/command-generation/adapters/trae.ts
  • src/core/command-generation/registry.ts

Comment thread src/core/command-generation/adapters/trae.ts

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping on Trae support. I think this needs one more pass before merge: add focused adapter/registry/update tests, escape the YAML frontmatter values, and update the supported-tools docs or cite the verified Trae command contract, since trunk currently documents Trae as skills-only.

- Add escapeYamlValue to trae adapter for safe YAML frontmatter output
- Add traeAdapter unit tests covering toolId, getFilePath, formatFile, and YAML escaping
- Add trae registry tests for get/has/getAll
- Update supported-tools.md: Trae command path from 'Not generated' to '.trae/commands/opsx/<id>.md'
@studyzy

studyzy commented Jun 12, 2026

Copy link
Copy Markdown
Author

Thanks for the review. All requested changes have been addressed and verified locally:

  1. YAML escaping: Added escapeYamlValue utility to the Trae adapter (consistent with claude.ts, cursor.ts, etc.) — both name and description fields are now properly escaped.

  2. Tests: Added focused adapter and registry tests covering toolId, getFilePath, formatFile, YAML special character escaping, newline escaping, and simple value pass-through.

  3. Supported-tools docs: Updated docs/supported-tools.md — Trae command path pattern changed from "Not generated" to .trae/commands/opsx/<id>.md.

Lint, build, and all command-generation tests pass.

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved latest head 7b5b114. The requested Trae follow-ups are in: YAML escaping for name/description, focused adapter and registry tests, and supported-tools docs. I reran the focused command-generation tests and typecheck in a temp worktree, and they passed. The Trae + weak-model explore-mode behavior in #1203 is a separate prompt/model compliance issue, not a blocker for this adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants